/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.SRV;

import com.google.gson.Gson;
import entity.SrcCureplanDoctor;
import entity.SrvCureplan;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.ejb.EJB;
import session.SrvCureplanFacade;
import session.SrvCureserviceFacade;
import session.SrcCureplanDoctorFacade;
import session.SrcCureplanDoctorManager;
import util.jQueryForm.jQueryFormFormatterUtil;
import util.jQueryForm.jQueryFormSelector;


/**
 *
 * @author nchanwut
 */
@WebServlet(name = "SRV_CurePlanProviderDetail",
loadOnStartup = 1,
urlPatterns = {"/SRV/CurePlanProviderDetail",
    "/SRV/CurePlanProviderDetail/formCureplanDoctor_Submit",
    "/SRV/CurePlanProviderDetail/getJson"})
public class SRV_CurePlanProviderDetail extends HttpServlet {

    private String sampleServletContext;
    @EJB
    private SrvCureserviceFacade srvCureserviceFacade;
    @EJB
    private SrcCureplanDoctorManager srcCurePlanDoctorManager;
    @EJB
    private SrvCureplanFacade srvCureplanFacade;
    @EJB
    private SrcCureplanDoctorFacade srvCureplanDoctorFacade;

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

        super.init(servletConfig);

        // initialize servlet with configuration information
        sampleServletContext = servletConfig.getServletContext().getInitParameter("sampleServletContext");
    }

    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");  // ensures that user input is interpreted as // 8-bit Unicode (e.g., for Czech characters)
        response.setContentType("text/json;charset=utf-8");
        //response.setCharacterEncoding("UTF-8");
        String userPath = request.getServletPath();
        HttpSession session = request.getSession();
        Boolean isDispatcher = true; //กำหนดว่า ต้องการให้เปลี่ยนหน้าหรือไม่ ? ต้องการ : ไม่ต้องการ

        // if category page is requested
        if (userPath.equals("/SRV/CurePlanProviderDetail")) {
            String curePlanId = (request.getParameter("curePlanId") != null) ? request.getParameter("curePlanId").trim() : "";
            String tmpcurePlanDoctorId = "";
            if (srvCureplanFacade.find(Long.parseLong(curePlanId)).getSrcCureplanDoctorCollection() != null && srvCureplanFacade.find(Long.parseLong(curePlanId)).getSrcCureplanDoctorCollection().size() > 0) {
                for (SrcCureplanDoctor tmp : srvCureplanFacade.find(Long.parseLong(curePlanId)).getSrcCureplanDoctorCollection()) {
                    tmpcurePlanDoctorId = tmp.getId().toString();
                    break;
                }
            }
            String curePlanDoctorId = (!tmpcurePlanDoctorId.isEmpty()) ? tmpcurePlanDoctorId : "";
            //@TODO : Perhap use session for security level

            request.setAttribute("curePlanDoctorId", curePlanDoctorId);

            userPath = "/SRV/CurePlanProviderDetail";
        }

        // use RequestDispatcher to forward request internally
        String url = "/WEB-INF/view" + userPath + ".jsp";

        try {
            if (isDispatcher) {
                request.getRequestDispatcher(url).forward(request, response);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");  // ensures that user input is interpreted as // 8-bit Unicode (e.g., for Czech characters)
        //response.setCharacterEncoding("UTF-8");
        //response.setContentType("text/json;charset=utf-8");

        Boolean isDispatcher = true; //กำหนดว่า ต้องการให้เปลี่ยนหน้าหรือไม่ ? ต้องการ : ไม่ต้องการ
        String userPath = request.getServletPath();
        HttpSession session = request.getSession();


        if (userPath.equals("/SRV/CurePlanProviderDetail/getJson")) { //Load Data For Page Load
            response.setContentType("text/json;charset=utf-8");
            String curePlanDoctorId = (request.getParameter("curePlanDoctorId") != null) ? request.getParameter("curePlanDoctorId").trim() : "";
            PrintWriter out;
            String strJson = "{}";
            if (!curePlanDoctorId.isEmpty()) {
                SrcCureplanDoctor srcCureplanDoctor = srvCureplanDoctorFacade.find(Long.parseLong(curePlanDoctorId));

                if (srcCureplanDoctor != null) {
                    try {
                        out = response.getWriter();
                        strJson = DisplayData(srcCureplanDoctor);
                        out.write(strJson);
                    } catch (Exception ex) {
                        //@TODO : Implement Error function to show on front
                        System.out.println("Error message" + ex.getMessage());
                    } finally {
                        /**
                         * Clear memory
                         */
                        srcCureplanDoctor = null;
                        out = null;
                        strJson = "";
                        //@TODO : Implement message function to show on front
                    }
                }
            } else { //when curePlanId is null or empty  donothing
                out = response.getWriter();
                out.write(strJson);
            }

            userPath = "/SRV/CureplanProviderDetail";
            isDispatcher = false;
        } else if (userPath.equals("/SRV/CurePlanProviderDetail/formCureplanDoctor_Submit")) {
            //Form Serialize Param
//          if set=>text/json firefox error
//          if only set response.setCharacterEncoding ie error must set charset=utf-8 in setContentType
            response.setContentType("text/html;charset=utf-8");
//            response.setCharacterEncoding("UTF-8");
            String txtSymptomComment = (request.getParameter("txtSymptomComment") != null) ? request.getParameter("txtSymptomComment").trim() : "";
            String txtAllergicHistoryComment = (request.getParameter("txtAllergicHistoryComment") != null) ? request.getParameter("txtAllergicHistoryComment").trim() : "";
            String txtDiseaseHistoryComment = (request.getParameter("txtDiseaseHistoryComment") != null) ? request.getParameter("txtDiseaseHistoryComment").trim() : "";
            String txtAttachHistoryComment = (request.getParameter("txtAttachHistoryComment") != null) ? request.getParameter("txtAttachHistoryComment").trim() : "";
            String txtRoomTypeComment = (request.getParameter("txtRoomTypeComment") != null) ? request.getParameter("txtRoomTypeComment").trim() : "";
            String txtPriceMinAcceptComment = (request.getParameter("txtPriceMinAcceptComment") != null) ? request.getParameter("txtPriceMinAcceptComment").trim() : "";
            String txtPriceMaxAcceptComment = (request.getParameter("txtPriceMaxAcceptComment") != null) ? request.getParameter("txtPriceMaxAcceptComment").trim() : "";
            String datDateMinAcceptComment = (request.getParameter("datDateMinAcceptComment") != null) ? request.getParameter("datDateMinAcceptComment").trim() : "";
            String datDateMaxAcceptComment = (request.getParameter("datDateMaxAcceptComment") != null) ? request.getParameter("datDateMaxAcceptComment").trim() : "";
            String uplAttachQuotation = (request.getParameter("uplAttachQuotation") != null) ? request.getParameter("uplAttachQuotation").trim() : "";
            String ddlHotelComment = (request.getParameter("ddlHotelComment") != null) ? request.getParameter("ddlHotelComment").trim() : "";
            String ddlSpecialistComment = (request.getParameter("ddlSpecialistComment") != null) ? request.getParameter("ddlSpecialistComment").trim() : "";
            //Hidden field
            String curePlanDoctorId = (request.getParameter("curePlanDoctorId") != null) ? request.getParameter("curePlanDoctorId").trim() : "";
            //Specify Submit button
            String btnSubmit = (request.getParameter("btnSubmit") != null) ? request.getParameter("btnSubmit").trim() : "";
            String btnReply = (request.getParameter("btnReply") != null) ? request.getParameter("btnReply").trim() : "";

            SrcCureplanDoctor srcCureplanDoctor;
            PrintWriter out;
            String strJson;
            try {
                /**
                 * Validate Data
                 */
                //@TODO : Validate Here (Server Side)
                /**
                 * Save CurePlanDoctorDetail
                 */
                srcCureplanDoctor = srcCurePlanDoctorManager.SaveCurePlanDoctorDetail(txtSymptomComment, txtAllergicHistoryComment, txtDiseaseHistoryComment, txtAttachHistoryComment, txtRoomTypeComment, txtPriceMinAcceptComment, txtPriceMaxAcceptComment, datDateMinAcceptComment, datDateMaxAcceptComment, uplAttachQuotation, ddlHotelComment, ddlSpecialistComment, curePlanDoctorId, btnSubmit, btnReply);

                /**
                 * Set Display Data Or Dispatcher
                 */
                out = response.getWriter();
                strJson = DisplayData(srcCureplanDoctor);
                out.write(strJson);

                /**
                 * Change Page
                 */
                userPath = "/SRV/CureplanProviderDetail";
                isDispatcher = false;
            } catch (Exception ex) {
                //@TODO : Implement Error function to show on front
                System.out.println("Error message" + ex.getMessage());
            } finally {
                /**
                 * Clear memory
                 */
                srcCureplanDoctor = null;
                out = null;
                strJson = "";
                //@TODO : Implement message function to show on front
            }


        }

        // use RequestDispatcher to forward request internally
        String url = "/WEB-INF/view" + userPath + ".jsp";

        try {
            if (isDispatcher) {
                request.getRequestDispatcher(url).forward(request, response);
            }
        } catch (Exception ex) {
            ex.printStackTrace();

        }

    }

    public String DisplayData(SrcCureplanDoctor srcCureplanDoctor) {
        /**
         * Set Message
         */
        String strMessage = "";//@TODO : Make string Message to Util class

        /**
         * Set Button Command
         */
        String ButtonCommand_wrapper = "";
        String btnBack = "<button type=\"button\" name=\"btnBack\" id=\"btnBack\" value=\"Back\">"
                + "<span>Back</span>"
                + "</button>";
        String btnManagePlan = "<button type=\"button\" name=\"btnManagePlan\" id=\"btnManagePlan\" value=\"ManagePlan\">"
                + "<span>Manage Plan</span>"
                + "</button>";
        String btnReset = "<input type=\"reset\" name=\"btnReset\" id=\"btnReset\" value=\"Reset\" />";
        String btnSaveDraft = "<button type=\"submit\" name=\"btnSaveDraft\" id=\"btnSaveDraft\" value=\"SaveDraft\">"
                + "<span>Save Draft</span>"
                + "</button>";
        String btnSubmit = "<input type=\"submit\" name=\"btnSubmit\" id=\"btnSubmit\" value=\"Submit\" />";

        /**
         * Bind Control Value&Properties
         */
        //Add value by value to Selector specify to jquery function
        Map<String, String> mapHtml = null;
        Map<String, String> mapText = null;
        Map<String, String> mapVal = null;
        Map<String, String> mapAddClass = null;
        Map<String, String> mapRemoveClass = null;
        Map<String, String> mapToggleClass = null;
        Map<String, String> mapDisplayControl = null;

        //Add/Remove Attribute To Selector
        List<jQueryFormSelector> mapAttrs = null;
        jQueryFormSelector attr = null;
        Map<String, String> mapAttrItem = null;
        Map<String, String> mapRemoveAttr = null;

        /**
         * Prepare DB value
         */
        DateFormat df = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
        //For srvCurePlan_doctor
        String strSymptomComment = "";
        String strAllergicHistoryComment = "";
        String strDiseaseHistoryComment = "";
        String strAttachHistoryComment = "";
        String strRoomTypeComment = "";
        String strPriceMinAcceptComment = "";
        String strPriceMaxAcceptComment = "";
        String strDateMinAcceptComment = "";
        String strDateMaxAcceptComment = "";
        String strAttachQuotation = "";
        String strHotelComment = "";
        String strSpecialistComment = "";
        Long intHotelComment = 0L;
        Long intSpecialistComment = 0L;
        if (srcCureplanDoctor != null) {
            strSymptomComment = (srcCureplanDoctor.getSymptom() != null) ? srcCureplanDoctor.getSymptom() : "";
            strAllergicHistoryComment = (srcCureplanDoctor.getAllergicHistory() != null) ? srcCureplanDoctor.getAllergicHistory() : "";
            strDiseaseHistoryComment = (srcCureplanDoctor.getDiseaseHistory() != null) ? srcCureplanDoctor.getDiseaseHistory() : "";
            strAttachHistoryComment = (srcCureplanDoctor.getAttachHistoryComment() != null) ? srcCureplanDoctor.getAttachHistoryComment() : "";
            strRoomTypeComment = (srcCureplanDoctor.getRoomType() != null) ? srcCureplanDoctor.getRoomType() : "";
            strPriceMinAcceptComment = (srcCureplanDoctor.getPriceMinAccept() != null) ? srcCureplanDoctor.getPriceMinAccept() : "";
            strPriceMaxAcceptComment = (srcCureplanDoctor.getPriceMaxAccept() != null) ? srcCureplanDoctor.getPriceMaxAccept() : "";
            strDateMinAcceptComment = (srcCureplanDoctor.getDateMinAccept() != null) ? srcCureplanDoctor.getDateMinAccept() : "";
            strDateMaxAcceptComment = (srcCureplanDoctor.getDateMaxAccept() != null) ? srcCureplanDoctor.getDateMaxAccept() : "";
            strAttachQuotation = (srcCureplanDoctor.getAttachQuotation() != null) ? srcCureplanDoctor.getAttachQuotation() : "";
            strHotelComment = (srcCureplanDoctor.getMHotel() != null) ? srcCureplanDoctor.getMHotel().getName() : "";
            strSpecialistComment = (srcCureplanDoctor.getMSpecialist() != null) ? srcCureplanDoctor.getMSpecialist().getName() : "";
            intHotelComment = (srcCureplanDoctor.getMHotel() != null) ? srcCureplanDoctor.getMHotel().getId() : 0;
            intSpecialistComment = (srcCureplanDoctor.getMSpecialist() != null) ? srcCureplanDoctor.getMSpecialist().getId() : 0;
        }
        //For srvCurePlan
        String strSymptom = "";
        String strAllergicHistory = "";
        String strDiseaseHistory = "";
        String strAttachHistory = "";
        String strRoomType = "";
        String strPriceMinAccept = "";
        String strPriceMaxAccept = "";
        String strDateMinAccept = "";
        String strDateMaxAccept = "";
        Boolean blRequestQuotation = null;
        String strHotel = "";
        String strSpecialist = "";
        SrvCureplan objSrvCureplan = srcCureplanDoctor.getSrvCureplan();
        if (objSrvCureplan != null) {
            strSymptom = (objSrvCureplan.getSymptom() != null) ? objSrvCureplan.getSymptom() : "";
            strAllergicHistory = (objSrvCureplan.getAllergicHistory() != null) ? objSrvCureplan.getAllergicHistory() : "";
            strDiseaseHistory = (objSrvCureplan.getDiseaseHistory() != null) ? objSrvCureplan.getDiseaseHistory() : "";
            strAttachHistory = (objSrvCureplan.getAttachHistory() != null) ? objSrvCureplan.getAttachHistory() : "";
            strRoomType = (objSrvCureplan.getRoomType() != null) ? objSrvCureplan.getRoomType() : "";
            strPriceMinAccept = (objSrvCureplan.getPriceMinAccept() != null) ? objSrvCureplan.getPriceMinAccept().toString() : "";
            strPriceMaxAccept = (objSrvCureplan.getPriceMaxAccept() != null) ? objSrvCureplan.getPriceMaxAccept().toString() : "";
            strDateMinAccept = (objSrvCureplan.getDateMinAccept() != null) ? df.format(objSrvCureplan.getDateMinAccept()) : "";
            strDateMaxAccept = (objSrvCureplan.getDateMaxAccept() != null) ? df.format(objSrvCureplan.getDateMaxAccept()) : "";
            blRequestQuotation = (objSrvCureplan.getRequestQuotation() != null && objSrvCureplan.getRequestQuotation() == true) ? objSrvCureplan.getRequestQuotation() : false;
            strHotel = (objSrvCureplan.getMHotel() != null) ? objSrvCureplan.getMHotel().getName() : "";
            strSpecialist = (objSrvCureplan.getMSpecialist() != null) ? objSrvCureplan.getMSpecialist().getName() : "";

        }

        try {
            /**
             * Bind Value By srvCurePlan.getStatus() Condition
             */
            if (objSrvCureplan.getStatus().equals("D")) {
                //Set Message By Status
                strMessage = "<div class=\"notification-box\"><p class=\"icon\"><img src=\"http://osc4.template-help.com/wt_32136/images/icon-note.png\" alt=\"\"></p>You currently draft your plan.<br/>Press 'Submit' to send request to 'Doctor' or 'Hospital</div>";

                /**
                 * Bind Html(innerHtml) : replace html to #'Selector'
                 */
                //ButtonCommand_wrapper = new StringBuilder().append(btnBack).append(btnManagePlan).append(btnReset).append(btnSaveDraft).append(btnSubmit).toString();
                mapHtml = new LinkedHashMap<String, String>();
                mapHtml.put("#message", strMessage);
                //For srvCurePlan
                mapHtml.put("#lblSymptom", strSymptom);
                mapHtml.put("#lblAllergicHistory", strAllergicHistory);
                mapHtml.put("#lblDiseaseHistory", strDiseaseHistory);
                mapHtml.put("#lblAttachHistory", strAttachHistory);
                mapHtml.put("#lblRoomType", strRoomType);
                mapHtml.put("#lblPriceMinAccept", strPriceMinAccept);
                mapHtml.put("#lblPriceMaxAccept", strPriceMaxAccept);
                mapHtml.put("#lblDateMinAccept", strDateMinAccept);
                mapHtml.put("#lblDateMaxAccept", strDateMaxAccept);
                mapHtml.put("#lblHotel", strHotel);
                mapHtml.put("#lblSpecialist", strSpecialist);
                //For srvCurePlan_doctor
                mapHtml.put("#lblSymptomComment", strSymptomComment);
                mapHtml.put("#lblAllergicHistoryComment", strAllergicHistoryComment);
                mapHtml.put("#lblDiseaseHistoryComment", strDiseaseHistoryComment);
                mapHtml.put("#lblAttachHistoryComment", strAttachHistoryComment);
                mapHtml.put("#lblRoomTypeComment", strRoomTypeComment);
                mapHtml.put("#lblPriceMinAcceptComment", strPriceMinAcceptComment);
                mapHtml.put("#lblPriceMaxAcceptComment", strPriceMaxAcceptComment);
                mapHtml.put("#lblDateMinAcceptComment", strDateMinAcceptComment);
                mapHtml.put("#lblDateMaxAcceptComment", strDateMaxAcceptComment);
                mapHtml.put("#lblAttachQuotation", strAttachQuotation);
                mapHtml.put("#lblHotelComment", strHotelComment);
                mapHtml.put("#lblSpecialistComment", strSpecialistComment);

                /**
                 * Bind Val : most use for bind value from DB to control(.value)
                 */
                mapVal = new LinkedHashMap<String, String>();
                //For Hidden Field
                mapVal.put("#curePlanDoctorId", srcCureplanDoctor.getId().toString());
                //For srvCurePlan_doctor
                mapVal.put("#txtSymptomComment", strSymptomComment);
                mapVal.put("#txtAllergicHistoryComment", strAllergicHistoryComment);
                mapVal.put("#txtDiseaseHistoryComment", strDiseaseHistoryComment);
                mapVal.put("#txtAttachHistoryComment", strAttachHistoryComment);
                mapVal.put("#txtRoomTypeComment", strRoomTypeComment);
                mapVal.put("#txtPriceMinAcceptComment", strPriceMinAcceptComment);
                mapVal.put("#txtPriceMaxAcceptComment", strPriceMaxAcceptComment);
                mapVal.put("#datDateMinAcceptComment", strDateMinAcceptComment);
                mapVal.put("#datDateMaxAcceptComment", strDateMaxAcceptComment);
                //mapHtml.put("#lblAttachQuotation", strAttachQuotation);
                //mapVal.put("#lblHotelComment", strHotelComment);
                //mapVal.put("#lblSpecialistComment", strSpecialistComment);

                /**
                 * Bind Display Control : Show/Hide Control by '1' = show, '0' = hide
                 */
                mapDisplayControl = new LinkedHashMap<String, String>();
                //Hide Control
                mapDisplayControl.put("#txtSymptomComment", "0");
                mapDisplayControl.put("#txtAllergicHistoryComment", "0");
                mapDisplayControl.put("#txtDiseaseHistoryComment", "0");
                mapDisplayControl.put("#txtAttachHistoryComment", "0");
                mapDisplayControl.put("#txtRoomTypeComment", "0");
                mapDisplayControl.put("#txtPriceMinAcceptComment", "0");
                mapDisplayControl.put("#txtPriceMaxAcceptComment", "0");
                mapDisplayControl.put("#datDateMinAcceptComment", "0");
                mapDisplayControl.put("#datDateMaxAcceptComment", "0");
                mapDisplayControl.put("#pnlAttachQuotation", "0");
                mapDisplayControl.put("#ddlHotelComment", "0");
                mapDisplayControl.put("#ddlSpecialistComment", "0");
                mapDisplayControl.put("#uniform-btnReset", "0");
                mapDisplayControl.put("#uniform-btnReply", "0");
                mapDisplayControl.put("#uniform-btnSubmit", "0");
                //Show Control
                mapDisplayControl.put("#lblSymptomComment", "1");
                mapDisplayControl.put("#lblAllergicHistoryComment", "1");
                mapDisplayControl.put("#lblDiseaseHistoryComment", "1");
                mapDisplayControl.put("#lblAttachHistoryComment", "1");
                mapDisplayControl.put("#lblRoomTypeComment", "1");
                mapDisplayControl.put("#lblPriceMinAccepCommentt", "1");
                mapDisplayControl.put("#lblPriceMaxAcceptComment", "1");
                mapDisplayControl.put("#lblDateMinAcceptComment", "1");
                mapDisplayControl.put("#lblDateMaxAcceptComment", "1");
                mapDisplayControl.put("#lblAttachQuotation", "1");
                mapDisplayControl.put("#lblHotelComment", "1");
                mapDisplayControl.put("#lblSpecialistComment", "1");

                /**
                 * Bind Add/Remove attribute for control : use for attribute checked, disabled or else
                 */
                //Add Attributes
                mapAttrs = new ArrayList<jQueryFormSelector>();
                attr = new jQueryFormSelector();
                attr.setId("#chkRequestQuotation");
                mapAttrItem = new LinkedHashMap<String, String>();

                if (blRequestQuotation) {
                    mapAttrItem.put("checked", "checked");
                    mapAttrItem.put("disabled", "disabled");
                } else {
                    mapAttrItem.put("disabled", "disabled");
//                    mapRemoveAttr.put("#chkRequestQuotation", "checked");
                }
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

                attr = new jQueryFormSelector();
                attr.setId("#ddlHotel option[value="+ intHotelComment +"]");
                mapAttrItem = new LinkedHashMap<String, String>();
                mapAttrItem.put("selected", "selected");
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

                attr = new jQueryFormSelector();
                attr.setId("#ddlSpecialist option[value="+ intSpecialistComment +"]");
                mapAttrItem = new LinkedHashMap<String, String>();
                mapAttrItem.put("selected", "selected");
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

            } else if (objSrvCureplan.getStatus().equals("W")) {
                //Set Message By Status
                strMessage = "<div class=\"info-box\"><p class=\"icon\"><img src=\"http://osc4.template-help.com/wt_32136/images/icon-info.png\" alt=\"\"></p>Waiting 'Doctor' or 'Hospital' for accepting your plan.<br/><br/></div>";

                /**
                 * Bind Html(innerHtml) : replace html to #'Selector'
                 */
                //ButtonCommand_wrapper = new StringBuilder().append(btnBack).append(btnManagePlan).append(btnReset).append(btnSaveDraft).append(btnSubmit).toString();
                mapHtml = new LinkedHashMap<String, String>();
                mapHtml.put("#message", strMessage);
                //For srvCurePlan
                mapHtml.put("#lblSymptom", strSymptom);
                mapHtml.put("#lblAllergicHistory", strAllergicHistory);
                mapHtml.put("#lblDiseaseHistory", strDiseaseHistory);
                mapHtml.put("#lblAttachHistory", strAttachHistory);
                mapHtml.put("#lblRoomType", strRoomType);
                mapHtml.put("#lblPriceMinAccept", strPriceMinAccept);
                mapHtml.put("#lblPriceMaxAccept", strPriceMaxAccept);
                mapHtml.put("#lblDateMinAccept", strDateMinAccept);
                mapHtml.put("#lblDateMaxAccept", strDateMaxAccept);
                mapHtml.put("#lblHotel", strHotel);
                mapHtml.put("#lblSpecialist", strSpecialist);
                //For srvCurePlan_doctor
                mapHtml.put("#lblSymptomComment", strSymptomComment);
                mapHtml.put("#lblAllergicHistoryComment", strAllergicHistoryComment);
                mapHtml.put("#lblDiseaseHistoryComment", strDiseaseHistoryComment);
                mapHtml.put("#lblAttachHistoryComment", strAttachHistoryComment);
                mapHtml.put("#lblRoomTypeComment", strRoomTypeComment);
                mapHtml.put("#lblPriceMinAcceptComment", strPriceMinAcceptComment);
                mapHtml.put("#lblPriceMaxAcceptComment", strPriceMaxAcceptComment);
                mapHtml.put("#lblDateMinAcceptComment", strDateMinAcceptComment);
                mapHtml.put("#lblDateMaxAcceptComment", strDateMaxAcceptComment);
                mapHtml.put("#lblAttachQuotation", strAttachQuotation);
                mapHtml.put("#lblHotelComment", strHotelComment);
                mapHtml.put("#lblSpecialistComment", strSpecialistComment);

                /**
                 * Bind Val : most use for bind value from DB to control(.value)
                 */
                mapVal = new LinkedHashMap<String, String>();
                //For Hidden Field
                mapVal.put("#curePlanDoctorId", srcCureplanDoctor.getId().toString());
                //For srvCurePlan_doctor
                mapVal.put("#txtSymptomComment", strSymptomComment);
                mapVal.put("#txtAllergicHistoryComment", strAllergicHistoryComment);
                mapVal.put("#txtDiseaseHistoryComment", strDiseaseHistoryComment);
                mapVal.put("#txtAttachHistoryComment", strAttachHistoryComment);
                mapVal.put("#txtRoomTypeComment", strRoomTypeComment);
                mapVal.put("#txtPriceMinAcceptComment", strPriceMinAcceptComment);
                mapVal.put("#txtPriceMaxAcceptComment", strPriceMaxAcceptComment);
                mapVal.put("#datDateMinAcceptComment", strDateMinAcceptComment);
                mapVal.put("#datDateMaxAcceptComment", strDateMaxAcceptComment);
                //mapHtml.put("#lblAttachQuotation", strAttachQuotation);
                //mapVal.put("#lblHotelComment", strHotelComment);
                //mapVal.put("#lblSpecialistComment", strSpecialistComment);

                /**
                 * Bind Display Control : Show/Hide Control by '1' = show, '0' = hide
                 */
                mapDisplayControl = new LinkedHashMap<String, String>();
                //Show Control
                mapDisplayControl.put("#txtSymptomComment", "1");
                mapDisplayControl.put("#txtAllergicHistoryComment", "1");
                mapDisplayControl.put("#txtDiseaseHistoryComment", "1");
                mapDisplayControl.put("#txtAttachHistoryComment", "1");
                mapDisplayControl.put("#txtRoomTypeComment", "1");
                mapDisplayControl.put("#txtPriceMinAcceptComment", "1");
                mapDisplayControl.put("#txtPriceMaxAcceptComment", "1");
                mapDisplayControl.put("#datDateMinAcceptComment", "1");
                mapDisplayControl.put("#datDateMaxAcceptComment", "1");
                mapDisplayControl.put("#pnlAttachQuotation", "1");
                mapDisplayControl.put("#ddlHotelComment", "1");
                mapDisplayControl.put("#ddlSpecialistComment", "1");
                mapDisplayControl.put("#uniform-btnReset", "1");
                mapDisplayControl.put("#uniform-btnReply", "1");
                mapDisplayControl.put("#uniform-btnSubmit", "1");
                //Hide Control
                mapDisplayControl.put("#lblSymptomComment", "0");
                mapDisplayControl.put("#lblAllergicHistoryComment", "0");
                mapDisplayControl.put("#lblDiseaseHistoryComment", "0");
                mapDisplayControl.put("#lblAttachHistoryComment", "0");
                mapDisplayControl.put("#lblRoomTypeComment", "0");
                mapDisplayControl.put("#lblPriceMinAccepCommentt", "0");
                mapDisplayControl.put("#lblPriceMaxAcceptComment", "0");
                mapDisplayControl.put("#lblDateMinAcceptComment", "0");
                mapDisplayControl.put("#lblDateMaxAcceptComment", "0");
                mapDisplayControl.put("#lblAttachQuotation", "0");
                mapDisplayControl.put("#lblHotelComment", "0");
                mapDisplayControl.put("#lblSpecialistComment", "0");

                /**
                 * Bind Add/Remove attribute for control : use for attribute checked, disabled or else
                 */
                //Add Attributes
                mapAttrs = new ArrayList<jQueryFormSelector>();
                attr = new jQueryFormSelector();
                attr.setId("#chkRequestQuotation");
                mapAttrItem = new LinkedHashMap<String, String>();

                if (blRequestQuotation) {
                    mapAttrItem.put("checked", "checked");
                    mapAttrItem.put("disabled", "disabled");
                } else {
                    mapAttrItem.put("disabled", "disabled");
//                    mapRemoveAttr.put("#chkRequestQuotation", "checked");
                }
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

                attr = new jQueryFormSelector();
                attr.setId("#ddlHotel option[value="+ intHotelComment +"]");
                mapAttrItem = new LinkedHashMap<String, String>();
                mapAttrItem.put("selected", "selected");
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

                attr = new jQueryFormSelector();
                attr.setId("#ddlSpecialist option[value="+ intSpecialistComment +"]");
                mapAttrItem = new LinkedHashMap<String, String>();
                mapAttrItem.put("selected", "selected");
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

            } else if (objSrvCureplan.getStatus().equals("E")) {
                //Set Message By Status
                strMessage = "<div class=\"error-box\"><p class=\"icon\"><img src=\"http://osc4.template-help.com/wt_32136/images/icon-error.png\" alt=\"\"></p>'Doctor' or 'Hospital' comment your plan. And request for change your plan.<br/><br/></div>";

                /**
                 * Bind Html(innerHtml) : replace html to #'Selector'
                 */
                //ButtonCommand_wrapper = new StringBuilder().append(btnBack).append(btnManagePlan).append(btnReset).append(btnSaveDraft).append(btnSubmit).toString();
                mapHtml = new LinkedHashMap<String, String>();
                mapHtml.put("#message", strMessage);
                //For srvCurePlan
                mapHtml.put("#lblSymptom", strSymptom);
                mapHtml.put("#lblAllergicHistory", strAllergicHistory);
                mapHtml.put("#lblDiseaseHistory", strDiseaseHistory);
                mapHtml.put("#lblAttachHistory", strAttachHistory);
                mapHtml.put("#lblRoomType", strRoomType);
                mapHtml.put("#lblPriceMinAccept", strPriceMinAccept);
                mapHtml.put("#lblPriceMaxAccept", strPriceMaxAccept);
                mapHtml.put("#lblDateMinAccept", strDateMinAccept);
                mapHtml.put("#lblDateMaxAccept", strDateMaxAccept);
                mapHtml.put("#lblHotel", strHotel);
                mapHtml.put("#lblSpecialist", strSpecialist);
                //For srvCurePlan_doctor
                mapHtml.put("#lblSymptomComment", strSymptomComment);
                mapHtml.put("#lblAllergicHistoryComment", strAllergicHistoryComment);
                mapHtml.put("#lblDiseaseHistoryComment", strDiseaseHistoryComment);
                mapHtml.put("#lblAttachHistoryComment", strAttachHistoryComment);
                mapHtml.put("#lblRoomTypeComment", strRoomTypeComment);
                mapHtml.put("#lblPriceMinAcceptComment", strPriceMinAcceptComment);
                mapHtml.put("#lblPriceMaxAcceptComment", strPriceMaxAcceptComment);
                mapHtml.put("#lblDateMinAcceptComment", strDateMinAcceptComment);
                mapHtml.put("#lblDateMaxAcceptComment", strDateMaxAcceptComment);
                mapHtml.put("#lblAttachQuotation", strAttachQuotation);
                mapHtml.put("#lblHotelComment", strHotelComment);
                mapHtml.put("#lblSpecialistComment", strSpecialistComment);

                /**
                 * Bind Val : most use for bind value from DB to control(.value)
                 */
                mapVal = new LinkedHashMap<String, String>();
                //For Hidden Field
                mapVal.put("#curePlanDoctorId", srcCureplanDoctor.getId().toString());
                //For srvCurePlan_doctor
                mapVal.put("#txtSymptomComment", strSymptomComment);
                mapVal.put("#txtAllergicHistoryComment", strAllergicHistoryComment);
                mapVal.put("#txtDiseaseHistoryComment", strDiseaseHistoryComment);
                mapVal.put("#txtAttachHistoryComment", strAttachHistoryComment);
                mapVal.put("#txtRoomTypeComment", strRoomTypeComment);
                mapVal.put("#txtPriceMinAcceptComment", strPriceMinAcceptComment);
                mapVal.put("#txtPriceMaxAcceptComment", strPriceMaxAcceptComment);
                mapVal.put("#datDateMinAcceptComment", strDateMinAcceptComment);
                mapVal.put("#datDateMaxAcceptComment", strDateMaxAcceptComment);
                //mapHtml.put("#lblAttachQuotation", strAttachQuotation);
                //mapVal.put("#lblHotelComment", strHotelComment);
                //mapVal.put("#lblSpecialistComment", strSpecialistComment);

                /**
                 * Bind Display Control : Show/Hide Control by '1' = show, '0' = hide
                 */
                mapDisplayControl = new LinkedHashMap<String, String>();
                //Hide Control
                mapDisplayControl.put("#txtSymptomComment", "0");
                mapDisplayControl.put("#txtAllergicHistoryComment", "0");
                mapDisplayControl.put("#txtDiseaseHistoryComment", "0");
                mapDisplayControl.put("#txtAttachHistoryComment", "0");
                mapDisplayControl.put("#txtRoomTypeComment", "0");
                mapDisplayControl.put("#txtPriceMinAcceptComment", "0");
                mapDisplayControl.put("#txtPriceMaxAcceptComment", "0");
                mapDisplayControl.put("#datDateMinAcceptComment", "0");
                mapDisplayControl.put("#datDateMaxAcceptComment", "0");
                mapDisplayControl.put("#pnlAttachQuotation", "0");
//                mapDisplayControl.put("#ddlHotelComment", "0");
//                mapDisplayControl.put("#ddlSpecialistComment", "0");
                mapDisplayControl.put("#uniform-ddlHotelComment", "0");
                mapDisplayControl.put("#uniform-ddlSpecialistComment", "0");
                mapDisplayControl.put("#uniform-btnReset", "0");
                mapDisplayControl.put("#uniform-btnReply", "0");
                mapDisplayControl.put("#uniform-btnSubmit", "0");
                //Show Control
                mapDisplayControl.put("#lblSymptomComment", "1");
                mapDisplayControl.put("#lblAllergicHistoryComment", "1");
                mapDisplayControl.put("#lblDiseaseHistoryComment", "1");
                mapDisplayControl.put("#lblAttachHistoryComment", "1");
                mapDisplayControl.put("#lblRoomTypeComment", "1");
                mapDisplayControl.put("#lblPriceMinAccepCommentt", "1");
                mapDisplayControl.put("#lblPriceMaxAcceptComment", "1");
                mapDisplayControl.put("#lblDateMinAcceptComment", "1");
                mapDisplayControl.put("#lblDateMaxAcceptComment", "1");
                mapDisplayControl.put("#lblAttachQuotation", "1");
                mapDisplayControl.put("#lblHotelComment", "1");
                mapDisplayControl.put("#lblSpecialistComment", "1");

                /**
                 * Bind Add/Remove attribute for control : use for attribute checked, disabled or else
                 */
                //Add Attributes
                mapAttrs = new ArrayList<jQueryFormSelector>();
                attr = new jQueryFormSelector();
                attr.setId("#chkRequestQuotation");
                mapAttrItem = new LinkedHashMap<String, String>();

                if (blRequestQuotation) {
                    mapAttrItem.put("checked", "checked");
                    mapAttrItem.put("disabled", "disabled");
                } else {
                    mapAttrItem.put("disabled", "disabled");
//                    mapRemoveAttr.put("#chkRequestQuotation", "checked");
                }
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

                attr = new jQueryFormSelector();
                attr.setId("#ddlHotel option[value="+ intHotelComment +"]");
                mapAttrItem = new LinkedHashMap<String, String>();
                mapAttrItem.put("selected", "selected");
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

                attr = new jQueryFormSelector();
                attr.setId("#ddlSpecialist option[value="+ intSpecialistComment +"]");
                mapAttrItem = new LinkedHashMap<String, String>();
                mapAttrItem.put("selected", "selected");
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

            } else if (objSrvCureplan.getStatus().equals("F")) {
                //Set Message By Status
                strMessage = "<div class=\"download-box\"><p class=\"icon\"><img src=\"http://osc4.template-help.com/wt_32136/images/icon-download.png\" alt=\"\"></p>Finish your plan.<br/><br/></div>";

                /**
                 * Bind Html(innerHtml) : replace html to #'Selector'
                 */
                //ButtonCommand_wrapper = new StringBuilder().append(btnBack).append(btnManagePlan).append(btnReset).append(btnSaveDraft).append(btnSubmit).toString();
                mapHtml = new LinkedHashMap<String, String>();
                mapHtml.put("#message", strMessage);
                //For srvCurePlan
                mapHtml.put("#lblSymptom", strSymptom);
                mapHtml.put("#lblAllergicHistory", strAllergicHistory);
                mapHtml.put("#lblDiseaseHistory", strDiseaseHistory);
                mapHtml.put("#lblAttachHistory", strAttachHistory);
                mapHtml.put("#lblRoomType", strRoomType);
                mapHtml.put("#lblPriceMinAccept", strPriceMinAccept);
                mapHtml.put("#lblPriceMaxAccept", strPriceMaxAccept);
                mapHtml.put("#lblDateMinAccept", strDateMinAccept);
                mapHtml.put("#lblDateMaxAccept", strDateMaxAccept);
                mapHtml.put("#lblHotel", strHotel);
                mapHtml.put("#lblSpecialist", strSpecialist);
                //For srvCurePlan_doctor
                mapHtml.put("#lblSymptomComment", strSymptomComment);
                mapHtml.put("#lblAllergicHistoryComment", strAllergicHistoryComment);
                mapHtml.put("#lblDiseaseHistoryComment", strDiseaseHistoryComment);
                mapHtml.put("#lblAttachHistoryComment", strAttachHistoryComment);
                mapHtml.put("#lblRoomTypeComment", strRoomTypeComment);
                mapHtml.put("#lblPriceMinAcceptComment", strPriceMinAcceptComment);
                mapHtml.put("#lblPriceMaxAcceptComment", strPriceMaxAcceptComment);
                mapHtml.put("#lblDateMinAcceptComment", strDateMinAcceptComment);
                mapHtml.put("#lblDateMaxAcceptComment", strDateMaxAcceptComment);
                mapHtml.put("#lblAttachQuotation", strAttachQuotation);
                mapHtml.put("#lblHotelComment", strHotelComment);
                mapHtml.put("#lblSpecialistComment", strSpecialistComment);

                /**
                 * Bind Val : most use for bind value from DB to control(.value)
                 */
                mapVal = new LinkedHashMap<String, String>();
                //For Hidden Field
                mapVal.put("#curePlanDoctorId", srcCureplanDoctor.getId().toString());
                //For srvCurePlan_doctor
                mapVal.put("#txtSymptomComment", strSymptomComment);
                mapVal.put("#txtAllergicHistoryComment", strAllergicHistoryComment);
                mapVal.put("#txtDiseaseHistoryComment", strDiseaseHistoryComment);
                mapVal.put("#txtAttachHistoryComment", strAttachHistoryComment);
                mapVal.put("#txtRoomTypeComment", strRoomTypeComment);
                mapVal.put("#txtPriceMinAcceptComment", strPriceMinAcceptComment);
                mapVal.put("#txtPriceMaxAcceptComment", strPriceMaxAcceptComment);
                mapVal.put("#datDateMinAcceptComment", strDateMinAcceptComment);
                mapVal.put("#datDateMaxAcceptComment", strDateMaxAcceptComment);
                //mapHtml.put("#lblAttachQuotation", strAttachQuotation);
                //mapVal.put("#lblHotelComment", strHotelComment);
                //mapVal.put("#lblSpecialistComment", strSpecialistComment);

                /**
                 * Bind Display Control : Show/Hide Control by '1' = show, '0' = hide
                 */
                mapDisplayControl = new LinkedHashMap<String, String>();
                //Hide Control
                mapDisplayControl.put("#txtSymptomComment", "0");
                mapDisplayControl.put("#txtAllergicHistoryComment", "0");
                mapDisplayControl.put("#txtDiseaseHistoryComment", "0");
                mapDisplayControl.put("#txtAttachHistoryComment", "0");
                mapDisplayControl.put("#txtRoomTypeComment", "0");
                mapDisplayControl.put("#txtPriceMinAcceptComment", "0");
                mapDisplayControl.put("#txtPriceMaxAcceptComment", "0");
                mapDisplayControl.put("#datDateMinAcceptComment", "0");
                mapDisplayControl.put("#datDateMaxAcceptComment", "0");
                mapDisplayControl.put("#pnlAttachQuotation", "0");
//                mapDisplayControl.put("#ddlHotelComment", "0");
//                mapDisplayControl.put("#ddlSpecialistComment", "0");
                mapDisplayControl.put("#uniform-ddlHotelComment", "0");
                mapDisplayControl.put("#uniform-ddlSpecialistComment", "0");
                mapDisplayControl.put("#uniform-btnReset", "0");
                mapDisplayControl.put("#uniform-btnReply", "0");
                mapDisplayControl.put("#uniform-btnSubmit", "0");
                //Show Control
                mapDisplayControl.put("#lblSymptomComment", "1");
                mapDisplayControl.put("#lblAllergicHistoryComment", "1");
                mapDisplayControl.put("#lblDiseaseHistoryComment", "1");
                mapDisplayControl.put("#lblAttachHistoryComment", "1");
                mapDisplayControl.put("#lblRoomTypeComment", "1");
                mapDisplayControl.put("#lblPriceMinAccepCommentt", "1");
                mapDisplayControl.put("#lblPriceMaxAcceptComment", "1");
                mapDisplayControl.put("#lblDateMinAcceptComment", "1");
                mapDisplayControl.put("#lblDateMaxAcceptComment", "1");
                mapDisplayControl.put("#lblAttachQuotation", "1");
                mapDisplayControl.put("#lblHotelComment", "1");
                mapDisplayControl.put("#lblSpecialistComment", "1");

                /**
                 * Bind Add/Remove attribute for control : use for attribute checked, disabled or else
                 */
                //Add Attributes
                mapAttrs = new ArrayList<jQueryFormSelector>();
                attr = new jQueryFormSelector();
                attr.setId("#chkRequestQuotation");
                mapAttrItem = new LinkedHashMap<String, String>();

                if (blRequestQuotation) {
                    mapAttrItem.put("checked", "checked");
                    mapAttrItem.put("disabled", "disabled");
                } else {
                    mapAttrItem.put("disabled", "disabled");
//                    mapRemoveAttr.put("#chkRequestQuotation", "checked");
                }
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

                attr = new jQueryFormSelector();
                attr.setId("#ddlHotel option[value="+ intHotelComment +"]");
                mapAttrItem = new LinkedHashMap<String, String>();
                mapAttrItem.put("selected", "selected");
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);

                attr = new jQueryFormSelector();
                attr.setId("#ddlSpecialist option[value="+ intSpecialistComment +"]");
                mapAttrItem = new LinkedHashMap<String, String>();
                mapAttrItem.put("selected", "selected");
                attr.setMapAttr(mapAttrItem);
                mapAttrs.add(attr);
            } else {
                //@TODO : Throw Exception message error
            }

            return jQueryFormFormatterUtil.getJSON(mapAttrs, mapRemoveAttr, mapHtml, mapText, mapVal, mapAddClass, mapRemoveClass, mapToggleClass, mapDisplayControl);

        } catch (Exception ex) {
            //@TODO : return error by throw exception
            return "{}";
        } finally {
            /**
             * Clear Memory
             */
            //@TODO : Clear Memory
        }

    }
}
